﻿using System;

namespace NullableTypes
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            Person p1 = new Person()
            {
                NoOfChildren = 2
            };
            Person p2 = new Person()
            {
                NoOfChildren = null
            };

            Person p3 = null;

            if (p1.NoOfChildren.HasValue)
            {
                int x = p1.NoOfChildren.Value;
                Console.WriteLine(p1.NoOfChildren);
            }

            if (p2.NoOfChildren != null)
            {
                Console.WriteLine(p2.NoOfChildren.Value);
            }

            // null coalescing operator(??)
            Console.WriteLine(p2.NoOfChildren ?? 0);

            // null propagation operator(?.)
            Console.WriteLine(p2?.NoOfChildren);

            Console.ReadKey();
        }
    }
}